/*
 * AccountTypeEnum.java
 *
 *  
 */
package org.msb.finance.app;

import org.msb.finance.data.Account;
import org.msb.finance.data.BankAccount;
import org.msb.finance.data.InvestmentAccount;

/**
 * 
 * 
 * @author Marc Boudreau
 * 
 */
public enum AccountTypeEnum {

	/**
	 * 
	 */
	BANK("Bank", BankAccount.class), //$NON-NLS-1$

	/**
	 * 
	 */
	CREDITCARD("Credit Card", null), //$NON-NLS-1$

	/**
	 * 
	 */
	LINECREDIT("Line of Credit", null), //$NON-NLS-1$

	/**
	 * 
	 */
	INVESTMENT("Investment", InvestmentAccount.class); //$NON-NLS-1$

	/*
	 * 
	 */
	private String name;

	/*
	 * 
	 */
	private Class<? extends Account> klass;

	private AccountTypeEnum(String name, Class<? extends Account> klass) {
		this.name = name;
		this.klass = klass;
	}

	/**
	 * 
	 * @return s
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * 
	 * @return s
	 */
	public Class<? extends Account> getAccountClass() {
		return this.klass;
	}

	/**
	 * 
	 * @return s
	 */
	public static AccountTypeEnum[] getAllTypes() {
		return new AccountTypeEnum[] { BANK, CREDITCARD, LINECREDIT, INVESTMENT };
	}

	/**
	 * 
	 * @param klass
	 * 
	 * @return s
	 */
	public static AccountTypeEnum getTypeForClass(Class<? extends Account> klass) {
		for (AccountTypeEnum type : getAllTypes()) {
			if (type.klass == klass) {
				return type;
			}
		}

		return null;
	}
}
